<?php
/**
 * Add a Remembrance Page listing for Funeral Directors
 * 
 * Allows funeral directors to ass a Remembrance page listing for people.
 */
/**
 * Provides emailing capabilities.
 */
require_once 'models/EmailModel.php';
/**
 * Brings together required parts for the page, such as the database, and html capabilites.
 */
require_once 'lib/controllerWithoutGetOrPost.php';
require_once 'models/FDSubmitModel.php';
require_once 'views/FDSubmitView.php';
require_once 'view/standard-noleftbar-top.php';
$email = new EmailModel();
$model = new FDSubmitModel($email);
$view = new FDSubmitView($html);
$permission = "FD Submit";
//MUST HAVE $permission SET BEFORE THIS!//
$userId = $_SESSION['user'];
if (empty($userId)) {
    echo $view->get('loginMessage');
} else {
    $sql = <<< EOT
        SELECT
            FuneralHomeID, Username, Permissions, Type, Email, AutoMail
            FROM Users WHERE ID = $userId

EOT;
    $result = $db->query($sql);
    if ($db->rowCount($result) > 0) {
        $User = $db->fetch($result);
    }
    $funeralHomeId = $User['FuneralHomeID'];
    $sql = <<< EOT
         SELECT
             Name
         FROM
             FuneralHome
                 INNER JOIN Users
                     ON FuneralHome.ID = Users.FuneralHomeID
         WHERE
             Users.FuneralHomeID = %d
EOT;
    $sql = sprintf($sql, $db->escape($funeralHomeId));
    $result = $db->query($sql);
    if ($db->rowCount($result) > 0) {
        $row = $db->fetch($result);
        $funeralHomeName = $db->unescape($row['Name']);
    }
    if ($_GET['action'] == 'complete') {
        $FORMfuneraldirector = $_POST['FDid'];
        if ($User['Type'] == 'Director') {
            $sql = "SELECT `ID`, `Name` FROM `FuneralHome` WHERE `ID` = '".$User['FuneralHomeID']."'";
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $row = $db->fetch($result);
            }
            $FORMfuneraldirector = $row['ID'];
            $FORMfuneralhomename = $row['Name'];
        }
        if (!empty($_POST['town'])) {
            $sql = 'SELECT `RegionID` FROM `CityTown` WHERE `ID` = '.intval($_POST['town']);
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $Town = $db->fetch($result);
            }
        }
        $FORMlname = $_POST['lname'];
        $FORMfname = $_POST['fname'];
        $FORMprevname = $_POST['prevname'];
        $FORMneename = $_POST['neename'];
        $FORMakaname = $_POST['akaname'];
        $FORMdeathdate = strftime("%Y-%m-%d %X", strtotime($db->escape($_POST['deathday'])." ".$db->escape($_POST['deathmonth'])." ".$db->escape($_POST['deathyear'])));
        $FORMbirthdate = strftime("%Y-%m-%d %X", strtotime($db->escape($_POST['birthday'])." ".$db->escape($_POST['birthmonth'])." ".$db->escape($_POST['birthyear'])));
        $FORMage = $_POST['age'];
        $FORMagemeasure = $_POST['agemeasure'];
        $FORMcitytownid = $_POST['town'];
        $FORMformercitytownid = $_POST['formertown'];
        $FORMregionid = $Town['RegionID'];
        $FORMcountryid = "412";//////
        $FORMcharityid = $_POST['charity'];
        $FORMaddedon = strftime("%Y-%m-%d %X", time());

        /*
         echo 'FOR JON-<br />'.$FORMlname.'<br />'.$FORMfname.'<br />'.$FORMprevname.'<br />'.$FORMneename.'<br />'.
         $FORMakaname.'<br />'.$FORMdeathdate.'<br />'.$FORMbirthdate.'<br />'.$FORMage.'<br />'.$FORMagemeasure.'<br />'
         $FORMcitytownid.'<br />'.$FORMformercitytownid.'<br />'.$FORMregionid.'<br />'.$FORMcountryid.'<br />'.
         $FORMcharityid.'<br />'.$FORMaddedon.'<br />'.$FORMfuneraldirector;
         */

        $sql = "INSERT INTO `".$dbname."`.`Person` ( `ID` , `Surname` , `FirstNames` , `FormerName` , `NeeName` , `AlsoKnownAs` , `DeathDate` , `BirthDate` , `Age` , `AgeMeasure` , `CityTownID` , `FormerCityTownID` , `RegionID` , `CountryID` , `CharityID` , `FuneralHomeID` , `OtherInfo` , `AddedOn` , `Photo` ) VALUES ( NULL , '".$db->escape($FORMlname)."', '".$db->escape($FORMfname)."', '".$db->escape($FORMprevname)."', '".$db->escape($FORMneename)."', '".$db->escape($FORMakaname)."', '".$db->escape($FORMdeathdate)."', '".$db->escape($FORMbirthdate)."', '".$db->escape($FORMage)."', '".$db->escape($FORMagemeasure)."', '".intval($FORMcitytownid)."', '".intval($FORMformercitytownid)."', '".intval($FORMregionid)."', '".intval($FORMcountryid)."', '0', '".$db->escape($FORMfuneraldirector)."', NULL , '".$db->escape($FORMaddedon)."', NULL );";
        $result = $db->query($sql);

        $sql = "SELECT `ID` FROM `Person` WHERE `Surname` LIKE '".$db->escape($FORMlname)."' AND `FirstNames` LIKE '".$db->escape($FORMfname)."' ORDER BY `ID` DESC";
        $result = $db->query($sql);
        if ($db->rowCount($result) != 0) {
            $Person = $db->fetch($result);
        }
        $FORMpersonID = $Person['ID'];

        $sql = "INSERT INTO `".$db->escape($dbname)."`.`FuneralHomePerson` ( `ID` , `PersonID` , `UserID` , `Charity`, `OpenForMonths` ) VALUES ( NULL , '".$db->escape($FORMpersonID)."', '".$db->escape($_SESSION['user'])."', '".$db->escape($_POST['charity'])."', '".$db->escape($_POST['sponsortime'])."' );";
        $result = $db->query($sql);

        $personName = $html->text($FORMfname).' '.$html->text($FORMlname);
        $toEmail = $User['Email']; // get via a User table foreign key connecting with FuneralDetails table
        $subject = 'New listing added, '.$personName;
        $message = $view->theteamSuccessEmail($FORMfuneralhomename, $personName, $FORMpersonID);
        $model->theteamEmail($subject, $message);
        if ($User['AutoMail'] == '1') {
            $message = $view->remembranceSuccessEmail($FORMfuneralhomename, $personName, $FORMpersonID);
            $model->remembranceSuccessEmail($toEmail, $subject, $message);
        }
        echo '
<ul id="forfuneraldirectors">
    <li>
        <h2><a href="remembrance.php?personid='.$FORMpersonID.'">Congratulations. Remembrance Page opened successfully.</a><br><small><small><a href="remembrance.php?personid='.$FORMpersonID.'">View page</a></small></small></h2><br /><div class="funeralhomeformleft">You will recieve a confirmation email shortly.<br /><br />Thank you for using A Memory Tree<br /><br /><a href="member.php">Back</a><br /></div>
    </li>
</ul>';

    } else {
        echo '
<ul id="forfuneraldirectors">
    <li>
        <h2 style="color:#000000;">Welcome '.$funeralHomeName.'</h2>
        <div><small><a href="member.php">Back to Member Page</a></small></div>
        <div class="funeralhomeformleft">
';
        if ($User['Type'] == 'Director') {
            /*
            $sql = "SELECT `ID`, `Name` FROM `FuneralHome` WHERE `ID` = '".$User['FuneralHomeID']."'";
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $row = $db->fetch($result);
            }
            $FHdetails;
            $sql = "SELECT  `ContactFirstName` , `ContactLastName` , `TelephoneDD` , `Telephone` , `Address1` , `Address2` , `Suburb` , `Fax` , `Email` , `Web` , `CountryID` , `RegionID` , `CityTownID` FROM `FuneralDetails` WHERE `FuneralHomeID` = ".$row['ID'];
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $FHdetails = $db->fetch($result);
            }
            $sql = "SELECT `Name` FROM `CityTown` WHERE `ID` = ".$FHdetails['CityTownID'];
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $CityTown = $db->fetch($result);
            }
            $sql = "SELECT `Name` FROM `Region` WHERE `ID` = ".$FHdetails['RegionID'];
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $Region = $db->fetch($result);
            }
            echo '
            <div style="text-align:left;">
               <img src="http://code.pitch.net.nz/mem/images/assets/funeralhomelogo.jpg" alt="Funeral Home Image" />
            </div>
            '.$row['Name'].'<br/>
            '.$FHdetails['Address1'].'<br/>
            '.$FHdetails['Suburb'].'<br/>
            '.$CityTown['Name'].'<br/>
            '.$FHdetails['Telephone'].'<br/>
            <a href="'.$FHdetails['Web'].'">'.$FHdetails['Web'].'</a><br/>';
             echo '
             <span class="links">
             <a href="#">modify details</a><br/>
             <a href="#">view history</a>
             </span>';
             */
        }
        echo '
            <form action="fdsubmit.php?action=preview" method="post">
               <div class="formcontainer">';
        if ($User['Type'] != 'Director') {
            echo '      <h3>Funeral Home</h3>
                  <label>Funeral Director *</label>
                  <select name="FDid">';
            $sql = "SELECT `ID`, `Name` FROM `FuneralHome` ORDER BY `Name` ASC";
            $result = $db->query($sql);
            if ($db->rowCount($result) != 0) {
                $FDlist = $db->fetch($result);
                while (!empty($FDlist)) {
                    echo '<option value="'.$FDlist['ID'].'"';
                    if ($_POST['FDid'] == $FDlist['ID']) {
                        echo ' selected="selected"';
                    }
                    echo ' >'.$FDlist['Name'].'</option>';
                    $FDlist = $db->fetch($result);
                }
            }
            echo '      </select>';
        }
        else{
            echo '<input type="hidden" name="FDid" value="'.$funeralHomeId.'">';
        }
        echo '
                  <h3>Deceased Information</h3>';
        if(($db->escape($_GET['action']) === 'preview')&&(empty($_POST['lname']))){
            echo '<label style="color:#990000;font-weight:bold;">';
        }else{
            echo '<label>';
        }
        echo 'Last Name *</label>
                  <input type="text"';
        if(($db->escape($_GET['action']) === 'preview')&&(empty($_POST['lname']))){
            echo ' style="border-color:#990000;background-color:#FFBB99;"';
        }
        echo ' id="lname" name="lname" value="'.$html->text($_POST['lname']).'" onBlur="javascript://document.getElementById(\'lname\').value=document.getElementById(\'lname\').value.toUpperCase();"/><br/>';
        if(($db->escape($_GET['action']) === 'preview')&&(empty($_POST['fname']))){
            echo '<label style="color:#990000;font-weight:bold;">';
        }else{
            echo '<label>';
        }
        echo 'First Name *</label>
                  <input  type="text"';
        if(($db->escape($_GET['action']) === 'preview')&&(empty($_POST['fname']))){
            echo ' style="border-color:#990000;background-color:#FFBB99;"';
        }
        echo ' name="fname" value="'.$html->text($_POST['fname']).'" /><br/>
                  <label>Also Known As</label>
                  <input  type="text" name="akaname" value="'.$html->text($_POST['akaname']).'"/><br/>
                  <label>Nee Name</label>
                  <input  type="text" id="neename" name="neename" value="'.$html->text($_POST['neename']).'" onBlur="javascript://document.getElementById(\'neename\').value=document.getElementById(\'neename\').value.toUpperCase();"/><br/>
                  <label>Former Name/s</label>
                  <input  type="text" id="prevname" name="prevname" value="'.$html->text($_POST['prevname']).'" onBlur="javascript:document.getElementById(\'prevname\').value=document.getElementById(\'prevname\').value.toUpperCase();"/><br/>
                  <label>Death Date *</label>
                  <select class="day" name="deathday">';
        for ($i = 1; $i <= 31; $i++) {
            echo '<option value="'.$i.'"';
            if ($i == intval($_POST['deathday'])) {
                echo ' selected="selected"';
            }
            echo '>'.$i.'</option>';
        }
        echo '
                  </select>
                  <select class="month" name="deathmonth">
                     <option value="January"';
        if ($db->escape($_POST['deathmonth']) === 'January') {
            echo ' selected="selected"';
        }
        echo '>January</option>
                     <option value="February"';
        if ($db->escape($_POST['deathmonth']) === 'February') {
            echo ' selected="selected"';
        }
        echo '>February</option>
                     <option value="March"';
        if ($db->escape($_POST['deathmonth']) === 'March') {
            echo ' selected="selected"';
        }
        echo '>March</option>
                     <option value="April"';
        if ($db->escape($_POST['deathmonth']) === 'April') {
            echo ' selected="selected"';
        }
        echo '>April</option>
                     <option value="May"';
        if ($db->escape($_POST['deathmonth']) === 'May') {
            echo ' selected="selected"';
        }
        echo '>May</option>
                     <option value="June"';
        if ($db->escape($_POST['deathmonth']) === 'June') {
            echo ' selected="selected"';
        }
        echo '>June</option>
                     <option value="July"';
        if ($db->escape($_POST['deathmonth']) === 'July') {
            echo ' selected="selected"';
        }
        echo '>July</option>
                     <option value="August"';
        if ($db->escape($_POST['deathmonth']) === 'August') {
            echo ' selected="selected"';
        }
        echo '>August</option>
                     <option value="September"';
        if ($db->escape($_POST['deathmonth']) === 'September') {
            echo ' selected="selected"';
        }
        echo '>September</option>
                     <option value="October"';
        if ($db->escape($_POST['deathmonth']) === 'October') {
            echo ' selected="selected"';
        }
        echo '>October</option>
                     <option value="November"';
        if ($db->escape($_POST['deathmonth']) === 'November') {
            echo ' selected="selected"';
        }
        echo '>November</option>
                     <option value="December"';
        if ($db->escape($_POST['deathmonth']) === 'December') {
            echo ' selected="selected"';
        }
        echo '>December</option>
                  </select>
                  <select class="year" name="deathyear" id="deathyear">';
        for ($i = 2009; $i > 1900; $i--) {
            echo '<option value="'.$i.'"';
            if ($i == intval($_POST['deathyear'])) {
                echo ' selected="selected"';
            }
            echo '>'.$i.'</option>';
        }
        echo '
                  </select><br/>
                  <label>Birth Date</label>
                  <select class="day" name="birthday">
                     <option value=""></option>';
        for ($i = 1; $i <= 31; $i++) {
            echo '<option value="'.$i.'"';
            if ($i == intval($_POST['birthday'])) {
                echo ' selected="selected"';
            }
            echo '>'.$i.'</option>';
        }
        echo '
                  </select>
                  <select class="month" name="birthmonth">
                     <option value=""></option>
                     <option value="January"';
        if ($db->escape($_POST['birthmonth']) === 'January') {
            echo ' selected="selected"';
        }
        echo '>January</option>
                     <option value="February"';
        if ($db->escape($_POST['birthmonth']) === 'February') {
            echo ' selected="selected"';
        }
        echo '>February</option>
                     <option value="March"';
        if ($db->escape($_POST['birthmonth']) === 'March') {
            echo ' selected="selected"';
        }
        echo '>March</option>
                     <option value="April"';
        if ($db->escape($_POST['birthmonth']) === 'April') {
            echo ' selected="selected"';
        }
        echo '>April</option>
                     <option value="May"';
        if ($db->escape($_POST['birthmonth']) === 'May') {
            echo ' selected="selected"';
        }
        echo '>May</option>
                     <option value="June"';
        if ($db->escape($_POST['birthmonth']) === 'June') {
            echo ' selected="selected"';
        }
        echo '>June</option>
                     <option value="July"';
        if ($db->escape($_POST['birthmonth']) === 'July') {
            echo ' selected="selected"';
        }
        echo '>July</option>
                     <option value="August"';
        if ($db->escape($_POST['birthmonth']) === 'August') {
            echo ' selected="selected"';
        }
        echo '>August</option>
                     <option value="September"';
        if ($db->escape($_POST['birthmonth']) === 'September') {
            echo ' selected="selected"';
        }
        echo '>September</option>
                     <option value="October"';
        if ($db->escape($_POST['birthmonth']) === 'October') {
            echo ' selected="selected"';
        }
        echo '>October</option>
                     <option value="November"';
        if ($db->escape($_POST['birthmonth']) === 'November') {
            echo ' selected="selected"';
        }
        echo '>November</option>
                     <option value="December"';
        if ($db->escape($_POST['birthmonth']) === 'December') {
            echo ' selected="selected"';
        }
        echo '>December</option>
                  </select>
                  <select class="year" name="birthyear" id="birthyear" onBlur=\'javascript:if(document.getElementById("deathyear").value-document.getElementById("birthyear").value<150){document.getElementById("age").value=document.getElementById("deathyear").value-document.getElementById("birthyear").value;}else{document.getElementById("age").value="";}\'>
                     <option value=""></option>';
        for ($i = 2009; $i > 1900; $i--) {
            echo '<option value="'.$i.'"';
            if ($i == $_POST['birthyear']) {
                echo ' selected="selected"';
            }
            echo '>'.$i.'</option>';
        }
        echo '
                  </select><br/>
                  <label>Age</label>
                  <input type="text" name="age" id="age" value="'.$html->text($_POST['age']).'"/><br/>
                  <label>Age Measure</label>
                  <select name="agemeasure">
                     <option value="y"';
        if ($_POST['agemeasure'] == 'y') {
            echo ' selected="selected"';
        }
        echo '>Years</option>
                     <option value="m"';
        if ($_POST['agemeasure'] == 'm') {
            echo ' selected="selected"';
        }
        echo '>Months</option>
                     <option value="d"';
        if ($_POST['agemeasure'] == 'd') {
            echo ' selected="selected"';
        }
        echo '>Days</option>
                  </select>					
                  <h3>Address Information</h3>
                  <label>Country *</label>
                  <select name="country">
                     <option value="New Zealand">New Zealand</option>
                  </select>
                  <label>City/Town</label>
                  <select name="town">
                     <option value="0">none</option>';
        $sql = "SELECT `ID`, `Name` FROM `CityTown` ORDER BY `Name` ASC";
        $result = $db->query($sql);
        if ($db->rowCount($result) != 0) {
            $Townlist = $db->fetch($result);
            while (!empty($Townlist)) {
                echo '<option value="'.$Townlist['ID'].'"';
                if ($_POST['town'] == $Townlist['ID']) {
                    echo ' selected="selected"';
                }
                echo ' >'.$Townlist['Name'].'</option>';
                $Townlist = $db->fetch($result);
            }
        }
        echo '
                  </select>
                  <label>Former City/Town</label>
                  <select name="formertown">
                     <option value="0">none</option>';
        $sql = "SELECT `ID`, `Name` FROM `CityTown` ORDER BY `Name` ASC";
        $result = $db->query($sql);
        if ($db->rowCount($result) != 0) {
            $Townlist = $db->fetch($result);
            while (!empty($Townlist)) {
                echo '<option value="'.$Townlist['ID'].'"';
                if ($_POST['formertown'] == $Townlist['ID']) {
                    echo ' selected="selected"';
                }
                echo ' >'.$Townlist['Name'].'</option>';
                $Townlist = $db->fetch($result);
            }
        }
        echo '
                  </select>
                  <h3>Donate to</h3>
                  <label>Charity</label>
                  <input type="text" name="charity" value="'.$html->text($_POST['charity']).'"/><br/>';
        /*
         echo '
         <select name="charity">
         <option value="">NONE</option>';
         $sql="SELECT `ID`, `Name` FROM `Charity` ORDER BY `Name` ASC";
         $result = $db->query($sql);
         if ($db->rowCount($result) != 0){
         while($Charitylist = $db->fetch($result)){
         echo '<option value="'.$Charitylist['ID'].'"';
         if($_POST['charity']==$Charitylist['ID']){echo ' selected="selected"';}
         echo '>'.$Charitylist['Name'].'</option>';
         }
         }
         */
        echo '
                  </select>
                  <h3>Remembrance Page is on...</h3>
                  <label>You can change</label>
                  <input type="text" name="tributepage" value="';
        if (!empty($_POST['tributepage'])) {
            echo $db->escape($_POST['tributepage']);
        } else {
            echo 'http://www.amemorytree.co.nz';
        }
        echo '"/>
                  <h3>Sponsor Page 
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <small style="font-size:10pt;color:#FF0000;">FREE for first 21 days!</small></h3>
                  <label>Keep open longer?</label>
                  <select name="sponsortime">
                     <option';
        echo '>Not at this time</option>
                     <option value="-1"';
        if ($_POST['sponsortime'] == '-1') {
            echo ' selected="selected"';
        }
        echo '>Email me after 3 weeks</option>
                     <option value="1"';
        if ($_POST['sponsortime'] == '1') {
            echo ' selected="selected"';
        }
        echo '>1 Month $19.90</option>
                     <option value="3"';
        if ($_POST['sponsortime'] == '3') {
            echo ' selected="selected"';
        }
        echo '>3 Months $29.90</option>
                     <option value="6"';
        if ($_POST['sponsortime'] == '6') {
            echo ' selected="selected"';
        }
        echo '>6 Months $49.90</option>
                     <option value="13"';
        if ($_POST['sponsortime'] == '13') {
            echo ' selected="selected"';
        }
        echo '>13 Months $99.90</option>
                  </select><br />
                  <h5 style="position:relative;left:140px;top:-5px;"><small>Invoiced to you at end of month less 10%</small></h5>
                  <br /><br />
                  <p style="text-align:right;"><input style="color: #c12a0b;background-color: #e6ddcc;font-family: Georgia, serif;text-transform: uppercase;" type="submit" value="';
        if(
                empty($_POST['fname'])
             || empty($_POST['lname'])
             || empty($_POST['deathday'])
             || empty($_POST['deathmonth'])
             || empty($_POST['deathyear'])
             || empty($_POST['country'])
        ){echo 'Continue';}else{echo 'Update';}
        echo '"/></p>
               </div>
            </form>
         </div>';

        if ($db->escape($_GET['action']) === 'preview') {
            if (!empty($_POST['region'])) {
                $sql = "SELECT `Name` FROM `Region` WHERE `ID` = ".$db->escape($_POST['region']);
                $result = $db->query($sql);
                if ($db->rowCount($result) != 0) {
                    $Region = $db->fetch($result);
                }
            }
            if (!empty($_POST['town'])) {
                $sql = "SELECT `Name` FROM `CityTown` WHERE `ID` = ".$db->escape($_POST['town']);
                $result = $db->query($sql);
                if ($db->rowCount($result) != 0) {
                    $Town = $db->fetch($result);
                }
            }
            if (!empty($_POST['formertown'])) {
                $sql = "SELECT `Name` FROM `CityTown` WHERE `ID` = ".$db->escape($_POST['formertown']);
                $result = $db->query($sql);
                if ($db->rowCount($result) != 0) {
                    $FormerTown = $db->fetch($result);
                }
            }
            /*
             if(!empty($_POST['charity'])){
             $sql="SELECT `Name` FROM `Charity` WHERE `ID` = ".$db->escape($_POST['charity']);
             $result = $db->query($sql);
             if ($db->rowCount($result) != 0){
             $Charity = $db->fetch($result);
             }
             }
             */
            echo '
        <div class="funeralhomeformright">
            <form action="fdsubmit.php?action=complete" method="post">';
///////

            if (
                empty($_POST['fname'])
             || empty($_POST['lname'])
             || empty($_POST['deathday'])
             || empty($_POST['deathmonth'])
             || empty($_POST['deathyear'])
             || empty($_POST['country'])
            ) {
                echo '<center><b>Oops, required fields have not been completed! Please fill them in and press Continue.</b></center>';
            } else {
                //QUERY FOR FD NAME, GIVEN ID in $_POST['FDid']
                $sql="SELECT `Name` FROM `FuneralHome` WHERE `ID` = ".$db->escape($_POST['FDid']);
                $result = $db->query($sql);
                if ($db->rowCount($result) != 0){
                    $FHdetail = $db->fetch($result);
                    $FHName = $FHdetail['Name'];
                }
                echo '
                <div style="text-align:left;">';
                echo 'Funeral Director: '.$FHName.'<br />';
                if (($_POST['lname']) && ($_POST['fname'])) {
                    echo '<br />First Names: '.$db->escape($_POST['fname']);
                    if(!empty($_POST['akaname'])){
                        echo ' ('.$db->escape($_POST['akaname']).')';
                    }
                    echo '<br />Last Name: '.$db->escape($_POST['lname']);
                    if (!empty($_POST['neename'])) {
                        echo '<br />Other Names: nee '.$html->text($_POST['neename']).'<input type="hidden" name="neename" value="'.$html->text($_POST['neename']).'">';
                    }
                    echo '<input type="hidden" name="fname" value="'.$db->escape($_POST['fname']).'"><input type="hidden" name="lname" value="'.$db->escape($_POST['lname']).'"><input type="hidden" name="akaname" value="'.$db->escape($_POST['akaname']).'">';
                }
                if (!empty($_POST['prevname'])) {
                    echo ' formerly '.$html->text($_POST['prevname']).'<input type="hidden" name="prevname" value="'.$html->text($_POST['prevname']).'">';
                }
                if (!empty($_POST['deathday']) && !empty($_POST['deathmonth']) && !empty($_POST['deathyear'])) {
                    echo '<br />Death Date: '.$html->text($_POST['deathday']).' '.$html->text($_POST['deathmonth']).' '.$html->text($_POST['deathyear']).'<input type="hidden" name="deathday" value="'.$html->text($_POST['deathday']).'"><input type="hidden" name="deathmonth" value="'.$html->text($_POST['deathmonth']).'"><input type="hidden" name="deathyear" value="'.$html->text($_POST['deathyear']).'">';
                }
                if (!empty($_POST['birthday']) && !empty($_POST['birthmonth']) && !empty($_POST['birthyear'])) {
                    echo '<br />Birth Date: '.$html->text($_POST['birthday']).' '.$html->text($_POST['birthmonth']).' '.$html->text($_POST['birthyear']).'<input type="hidden" name="birthday" value="'.$html->text($_POST['birthday']).'"><input type="hidden" name="birthmonth" value="'.$html->text($_POST['birthmonth']).'"><input type="hidden" name="birthyear" value="'.$html->text($_POST['birthyear']).'">';
                }
                if (!empty($_POST['age'])) {
                    echo '<br />Age: '.$html->text($_POST['age']).' '.$html->text($_POST['agemeasure']).'<input type="hidden" name="age" value="'.$html->text($_POST['age']).'"><input type="hidden" name="agemeasure" value="'.$html->text($_POST['agemeasure']).'"><br />';
                }
                /*
                 if(!empty($_POST['town'])){echo 'From: '.$html->text($Town['Name']).', '.$html->text($Region['Name']).', '.$html->text($_POST['country']).'<input type="hidden" name="town" value="'.$html->text($_POST['town']).'"><input type="hidden" name="region" value="'.$html->text($_POST['region']).'"><input type="hidden" name="country" value="'.$html->text($_POST['country']).'"><br />';}
                 if(!empty($_POST['formertown'])){echo 'Previously From: '.$html->text($FormerTown['Name']).', '.$html->text($_POST['country']).'<input type="hidden" name="formertown" value="'.$html->text($_POST['formertown']).'"><br /><br />';}
                 */
                if (!empty($_POST['charity'])) {
                    echo '<br />Charity: '.$html->text($_POST['charity']).'<input type="hidden" name="charity" value="'.$html->text($_POST['charity']).'">';
                }
                if (!empty($_POST['tributepage'])) {
                    if($db->escape($_POST['tributepage'])==="http://www."){
                    $tributePage="http://www.amemorytree.co.nz";
                    }else{
                    $tributePage=$html->text($_POST['tributepage']);
                    }
                    echo '<br />Online URL: '.$tributePage.'<input type="hidden" name="tributepage" value="'.$tributePage.'"><br />';
                }
                if (!empty($_POST['sponsortime'])) {
                    echo '<br />Page Sponsorship: ';
                    if (intval($_POST['sponsortime']) === -1) {
                        echo ' Mail after 3 weeks.<input type="hidden" name="sponsortime" value="'.$html->text($_POST['sponsortime']).'">';
                    }
                    else if (intval($_POST['sponsortime']) === 1) {
                        echo ' 1 Month $19.90<input type="hidden" name="sponsortime" value="'.$html->text($_POST['sponsortime']).'">';
                    }
                    else if (intval($_POST['sponsortime']) === 3) {
                        echo ' 3 Months $29.90<input type="hidden" name="sponsortime" value="'.$html->text($_POST['sponsortime']).'">';
                    }
                    else if (intval($_POST['sponsortime']) === 6) {
                        echo ' 6 Months $49.90<input type="hidden" name="sponsortime" value="'.$html->text($_POST['sponsortime']).'">';
                    }
                    else if (intval($_POST['sponsortime']) === 13) {
                        echo ' 13 Months $99.90<input type="hidden" name="sponsortime" value="'.$html->text($_POST['sponsortime']).'">';
                    }
                    else {
                        echo ' Not at this time.';
                    }
                    echo '<br />';
                }
                echo '
                      <br /><br /><input type="hidden" name="FDid" value="'.intval($_POST['FDid']).'">
                      <p><b>Update Information</b></p>
                      Use the form on the left to update details, and select Update<br /><br />';
                //echo'<textarea rows="7" style="overflow:auto;"></textarea><br /><input type="submit" value="Edit/Submit"><br />';
                echo '<p><b>Create Remembrance Page</b></p>
                      Use the button below to open the Remembrance page.<br /><br />';
                echo '<label style="color:#FF0000;width:300px;margin-bottom:5px;" onClick="javascript:if(document.getElementById(\'confirmbox\').checked==true){document.getElementById(\'createpagebutton\').disabled=false;document.getElementById(\'createpagebutton\').style.color=\'#c12a0b\';}else{document.getElementById(\'createpagebutton\').disabled=true;document.getElementById(\'createpagebutton\').style.color=\'#666666\';}"><input type="checkbox" id="confirmbox"/>*I have checked both the spelling and case type of the name. <small style="color:#000000;">Note: If you have typed "smith" it will appear as "smith" not "Smith"</small></label>';
                //Use javascript to disable the button, and javascript to enable it when the checkbox is checked. BUT the button is enabled if javascript has been disabled (for you Paul ;P )
                echo '<p style="text-align:right;"><input type="submit" id="createpagebutton"  value="Create Page" style="border-width:1px;border-style:solid;border-color:#e5dbc7;color:#c12a0b;background-color:#e6ddcc;font-family:Georgia,serif;text-transform:uppercase;width:240px;" /></p>';
                echo '<script type="text/javascript">if(document.getElementById(\'confirmbox\').checked==true){document.getElementById(\'createpagebutton\').disabled=false;document.getElementById(\'createpagebutton\').style.color=\'#c12a0b\';}else{document.getElementById(\'createpagebutton\').disabled=true;document.getElementById(\'createpagebutton\').style.color=\'#666666\';}</script>';
            }
            echo '
               </div>
            </form>';
        }
        echo '
         </div><br /><br />
   </li>
</ul>';
    }
}
require_once 'view/standard-noads-bottom.php';
?>
